package com.qxzn.app.page.robot;

import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.widget.TextView;

import com.qxzn.app.page.BaseActivity;
import com.qxzn.app.util.AppUtil;
import com.qxzn.app.util.CommonUtil;
import com.qxzn.app.util.Constant;
import com.qxzn.app.page.R;
import com.qxzn.app.page.R2;

import butterknife.BindView;
import butterknife.OnClick;

public class AddRobotNoticeActivity1 extends BaseActivity {
    @BindView(R2.id.tv_sub_title)
    TextView tvSubTitle;
    @BindView(R2.id.tv_content)
    TextView tvContent;
    @BindView(R2.id.tv_retry)
    TextView tvRetry;

    @Override
    protected int initLayout() {
        return R.layout.activity_add_robot_notice1;
    }

    @Override
    protected void initView() {
        iv_back.setOnClickListener(this);
    }

    @Override
    protected void iniTitleBar() {
        tv_title.setText("提示");
    }

    @Override
    protected void initData(Bundle savedInstanceState) {
        tvSubTitle.setText(getIntent().getStringExtra(Constant.PutExtraKey.TITLE));
        tvContent.setText(getIntent().getStringExtra(Constant.PutExtraKey.CONTENT));
        tvContent.setOnLongClickListener(new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View v) {
                CommonUtil.copyToClipboard(AddRobotNoticeActivity1.this, tvContent.getText().toString().trim());
                AppUtil.showToast(AddRobotNoticeActivity1.this, "内容已复制到剪贴板");
                return true;
            }
        });
        if (getIntent().getIntExtra("type", 0) == 1) {
            tvRetry.setVisibility(View.VISIBLE);
        }
    }

    @Override
    public void onClick(View view) {
        if (view.getId() == R.id.iv_back) {
            setResult(RESULT_OK);
            finish();
        }
    }

    @OnClick(R2.id.tv_retry)
    public void onViewClicked() {
        setResult(RESULT_OK);
        finish();
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_DOWN) {
            setResult(RESULT_OK);
            finish();
            return true;
        }
        return super.onKeyDown(keyCode, event);
    }

}
